﻿using System;

/*Write a program that finds the sequence of maximal sum in given array. Example:
	{2, 3, -6, -1, 2, -1, 6, 4, -8, 8}  {2, -1, 6, 4}
	Can you do it with only one loop (with single scan through the elements of the array)?
*/

    class MaximalSum
    {
        static void Main()
        {
            int[] array = { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };
            int maxSum = int.MinValue;

            for (int i = 0; i < array.Length; i++)
            {
                int curSum = 0;
                for (int j = i; j < array.Length; j++)
                {
                    curSum += array[j];

                    if (curSum > maxSum)
                    {
                        maxSum = curSum;
                    }
                }
                
            }
            Console.WriteLine(maxSum);
        }
    }

